package com.td.core.pathfinding;

import com.td.core.obj.TDPoint;

public class PathPoint extends TDPoint{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private PathPoint parent;
	private PathPoint target;
	private int movementCost; //G
	private int estimatedCost; //H
	private int risk;
	
	private static int NORMAL_MOVE = 10;
	private static int DIAGONAL_MOVE = 14;
	
	
	public PathPoint(int x, int y) {
		super(x, y);
	}
	
	public PathPoint(int x, int y, PathPoint target) {
		super(x, y);
		this.target = target;
	}

	
	public void setEstimatedCost(int estimatedCost) {
		this.estimatedCost = estimatedCost;
	}
	
	public void setTarget(PathPoint target) {
		this.target = target;
	}

	public PathPoint getParent() {
		return parent;
	}

	public int getCost() {
		return estimatedCost + movementCost + risk;
	}
	
	public int getMovementCost() {
		return movementCost;
	}
	
	public void recalculateMovementCost() {
		movementCost = calculateMovementCost(parent);
	}

	public void setParent(PathPoint parent) {
		this.parent = parent;
	}


	public void recalculateCost() {	
		estimatedCost = calculateEstimatedCost(target);
		movementCost = calculateMovementCost(parent);
	}
		
	public int calculateMovementCost(PathPoint parent) {
		
		if(parent == null)
			return 0;
		else {
			if(getX() != parent.getX() && getY() != parent.getY())
				return parent.movementCost + DIAGONAL_MOVE;
			else 
				return parent.movementCost + NORMAL_MOVE;
		}
	}
	
	public int calculateEstimatedCost(PathPoint target) {
		
		return Math.abs(target.getX() - this.getX()) + Math.abs(target.getY() - this.getY());
	}
	
	public void setRisk(int risk) {
		this.risk = risk;
	}
	

	
	
	
	
	
	
}
